/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ticketManager.controller;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import ticketManager.ejb.ProblemDAO;
import ticketManager.ejb.ManagerHelper;
import ticketManager.ejb.ProductDAO;
import ticketManager.model.ManagerUser;
import ticketManager.model.Problem;
import ticketManager.model.Product;

/**
 *
 * @author luchenyuxx
 */
@Named
@RequestScoped
public class ListProblemsController {

    @EJB
    ProblemDAO pd;
    @EJB
    ProductDAO proDAO;
    private List<Problem> newProblems = new ArrayList<>();
    private List<Problem> solvedProblems = new ArrayList<>();
    private List<Problem> transferProblems = new ArrayList<>();
    private List<Problem> inWorkProblems = new ArrayList<>();
    private List<Problem> allProblems = new ArrayList<>();
    private List<Problem> problemsByProcess = new ArrayList<>();

    private List<Problem> temp = new ArrayList<>();
    private List<Problem> temp1 = new ArrayList<>();
    private List<Product> temp2 = new ArrayList<>();
    
    private String select_pro_title;
    private ArrayList<String> pro_titles=new ArrayList<>();

    private Product select_pro;

    public String getSelect_pro_title() {
        return select_pro_title;
    }

    public void setSelect_pro_title(String select_pro_title) {
        this.select_pro_title = select_pro_title;
    }

    public Product getSelect_pro() {
        return select_pro;
    }

    public void setSelect_pro(Product select_pro) {
        this.select_pro = select_pro;
    }

    public List<Problem> getTemp() {
        return temp;
    }

    public List<Problem> getNewProblems() {
        return newProblems;
    }

    public List<Problem> getSolvedProblems() {
        return solvedProblems;
    }

    public List<Problem> getTransferProblems() {
        return transferProblems;
    }

    public List<Problem> getInWorkProblems() {
        return inWorkProblems;
    }

    public List<Problem> getAllProblems() {
        return allProblems;
    }

    public String listNewProblems() {
        newProblems = pd.getNewProblems();
        temp = newProblems;
        return "listNewProblems";
    }

    public String listSolvedProblems() {
        solvedProblems = pd.getSolvedProblems();
        temp = solvedProblems;
        return "listSolvedProblems";
    }

    public String listTransferProblems() {
        transferProblems = pd.getTransferProblems();
        temp = transferProblems;
        return "listTransferProblems";
    }

    public String listInWorkProblems() {
        inWorkProblems = pd.getInWorkProblems();
        temp = inWorkProblems;
        return "listInWorkProblems";
    }

    public String listAllProblems() {
        allProblems = pd.getAllProblems();
        temp = allProblems;
        return "listAllProblems";
    }

    public String listProblemsByProcess() {
        System.out.println("eeee");
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ManagerUser m = (ManagerUser) facesContext.getExternalContext().getSessionMap().get("user");
        problemsByProcess = pd.getProblemsByProcess(m);
        temp = problemsByProcess;
        return "listProblemsByProcess";
    }

    public List<Problem> getTemp1() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ManagerUser m = (ManagerUser) facesContext.getExternalContext().getSessionMap().get("user");
        problemsByProcess = pd.getProblemsByProcess(m);
        temp1 = problemsByProcess;
        return temp1;
    }

    public ArrayList<String> getPro_titles() {

        temp2 = proDAO.getAllProduct();
         Iterator i = temp2.iterator();
        while (i.hasNext()) {
            pro_titles.add(((Product) i.next()).getTitle());
        }
        return pro_titles;
    }

    public void listProblemsByProduct() {
        System.out.println("fff:" + select_pro_title);
        Product pro1 = proDAO.getProductByTitle(select_pro_title);
        temp = pd.getProblemsByProduct(pro1);
        pro_titles.clear();
    }

    public String changeURL() {
        return "changeStatusURL";
    }
}
